﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;

public partial class ManageCenter_AddUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        Users user = new Users();
        user.GetUserByUserName(txbusername.Text);
        if (user!=null)
            WebHelper.Alert("用户名已存在！");
        else
        {
            user = new Users();
            user.UserName = txbusername.Text;
            user.Password = txbpwd.Text;
            user.UserType = ddltype.SelectedValue;
            bool succ=false;
            if (ddltype.SelectedValue == "街道办事处" || ddltype.SelectedValue == "辖区房管所")
            {
                if (ddlstreet.SelectedValue == "海曙")
                    WebHelper.Alert("请选择街道");
                else
                {
                    user.UserStreet = ddlstreet.SelectedValue;
                    succ = new Users().AddNewUser(user);
                }
            }
            else
            {
                user.UserStreet = "海曙";
                succ = new Users().AddNewUser(user);
            }
            if (succ)
            {
                WebHelper.AlertAndCloseThenRefreshLastPage("添加成功");
            }
            else
                WebHelper.Alert("添加失败！");
        }
    }
}
